package com.example.exercise.appmanage.user.controller;

import com.example.exercise.core.base.dto.BaseResponse;
import com.example.exercise.appmanage.user.dto.response.UserResponse;
import com.example.exercise.appmanage.user.mapper.entity.UserEntity;
import com.example.exercise.appmanage.user.service.MgUserService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("mg/user")
//@Api(description = "用户 -- 登陆、注册、改密码、安全退出")
public class MgUserController {

    @Resource
    private MgUserService userService;

//    @ApiOperation(value = "获取管理员列表", notes = "获取管理员列表")
    @RequestMapping(value = "/getUserList", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Map<String,Object>> getUserList(String userName, @RequestParam Integer currentPage, @RequestParam Integer pageSize) {
        BaseResponse<Map<String,Object>> baseResponse = new BaseResponse<>();
        List<UserResponse> userResponses = userService.getUserList(userName, currentPage, pageSize);
        Integer count = userService.getCount(userName);
        Map<String,Object> map = new HashMap<>();
        map.put("count",count);
        map.put("list",userResponses);
        baseResponse.ok(map);
        return baseResponse;
    }

//    @ApiOperation(value = "查详情", notes = "查详情")
    @RequestMapping(value = "/findById", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> findById(@RequestParam Integer userId1) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        UserEntity userEntity = userService.findByUserId(userId1);
        if(userEntity == null){
            baseResponse.setCode(-12);
            baseResponse.setMsg("数据为空");
        }else{
            baseResponse.ok(userEntity);
        }
        return baseResponse;
    }

//    @ApiOperation(value = "修改启用状态", notes = "修改启用状态")
    @RequestMapping(value = "/modifyUseState", method = {RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE})
    public BaseResponse<Object> modifyUseState(@RequestParam Integer userId1) {
        BaseResponse<Object> baseResponse = new BaseResponse<>();
        userService.modifyUseState(userId1);
        baseResponse.ok();
        return baseResponse;
    }

}
